<%- include("components/header",{type:'my'}) %>

<div id="fh5co-page">
	<div id="fh5co-main">
		<div class="posts">
			<% posts.forEach(function(res){ %>
				<div>
					<!-- <img class="userAvator" src="images/<%= res.avator %>" onerror="this.src='http://blog.wclimb.site/images/default.jpg'"> -->
					<div class="title"><a href="/posts/<%= res.id %>"><%- res.title %></a></div>
					<div class="msg">
						<span title="<%= res.name %>">作者: <%= res.name %></span>
						<span>评论数：<%= res.comments %></span>
						<span>浏览量：<%= res.pv %></span>
						<span>发表时间：<%= res.moment %></span>
					</div>
					<div class="text-center toView"><a class="btn btn-primary" href="/posts/<%= res.id %>">阅读全文</a></div>
				</div>
			<% }) %>
		</div>
		<div style="margin-top: 30px" class="pagination" id="page"></div>
	</div>
</div>

<script>
	pagination({
		selector: '#page',
		totalPage: '<%= postsPageLength %>',
		currentPage: 1,
		prev: '上一页',
		next: '下一页',
		first: true,
		last: true,
		showTotalPage: true,
		count: 2//当前页前后显示的数量
	},function(val){
		// 当前页
		$.ajax({
			url: "posts/self/page",
			type: 'POST',
			data:{
				page: val,
				name: location.search.slice(1).split('=')[1]
			},
			cache: false,
			success: function (res) {
				if (res != 'error') {
					$('.posts').html(' ')
					$.each(res, function(i,val){
						$('.posts').append(
							'<div>' +
								'<div class=\"title\"><a href=\"/posts/' + val.id + '\">' + val.title + '</a></div>' +
								'<div class=\"msg\">' +
									'<span title="' + val.name + '">作者: ' + val.name + '</span>' +
									'<span>评论数：' + val.comments + '</span>' +
									'<span>浏览量：' + val.pv + '</span>' +
									'<span>发表时间：' + val.moment.substr(0, 10) + '</span>' +
								'</div>' +
								'<div class=\"text-center toView\">' +
									'<a class=\"btn btn-primary\" href=\"/posts/' + val.id + '\">阅读全文</a>' +
								'</div>' +
							'</div>'
						);
					})
				}else{
					console.log('分页不存在')
				} 
			}
		})
	
	})
</script>

<%- include("components/footer") %>